package me.zk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @Author: zhang kai
 * @Date: 2022/07/12
 * @Description:
 */
public class Demo3 {
    public static void main(String[] args) {
        Function<String, Integer> f = String::length;
        List<Integer> l = map(Arrays.asList("lambda","in"), f);
        //List<Integer> l = map(Arrays.asList("lambda","in"), (String s) -> s.length());
    }
    public static <T, R> List<R> map(List<T> list, Function<T,R> f) {
       List<R> result = new ArrayList<>();
       for (T s : list) {
           result.add(f.apply(s));
       }
       return result;
    }
}
